package com.shiguiwu.springmybatis.javabase.regex;

import lombok.extern.slf4j.Slf4j;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description: 正则表达式
 * 注意，使用字符串matches方法很慢，也可以用
 * @author: stone
 * @date: Created by 2022/5/29 13:57
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.regex
 */
@Slf4j
public class RegexTests {

    //匹配数字
    public static Pattern DATA_MATCH = Pattern.compile("\\d+");

    public static Pattern DATA_COUNT =  Pattern.compile("\\d{3}");

    public static void main(String[] args) {
        String reg = "\\d+";

        log.info(" 字符串方式 ==> {}","12121".matches(reg));

        log.info("是否匹配 ====> {}", DATA_MATCH.matcher("3213123").matches());
        log.info("是否匹配 ====> {}", DATA_COUNT.matcher("1231").matches());

        Matcher matcher = DATA_MATCH.matcher("231321");

        while (matcher.find()) {
            //System.out.println(matcher.start() + "->" + matcher.end());
            //System.out.println(matcher.start() + "->" + matcher.end());
            log.info("find ==>{}" ,matcher.start(2) );
        }

    }
}
